import sys
sys.path.append('../kernel')
from model import Model
class JobModel(Model):
    def __init__(self):
        # 链接数据库
        super().__init__()
    # 判断数据是否存在
    def isCity_exists(self,city_name):
        # 执行查询
        sql = "select id,`name` from city WHERE `name`='%s'" % city_name
        # sql = "select id,`name` from city"
        self.cursor.execute(sql)
        if(self.cursor.rowcount>=1):
            return 1
        else:
            return 0
    #添加城市
    def add_job(self,job_vocation,dt,dd):
        for name in dd:
            sql = "INSERT INTO job_name SET job_vocation=%s,job_type=%s,job_name=%s"
            self.cursor.execute(sql,(job_vocation,dt,name))
            self.conn.commit()#提交

    def __del__(self):
        #计数数据库链接
        self.cursor.close()
        self.conn.close()